import moment from "moment";

export const hasMenu = (children: any) => children ? children.filter((v: { ignore: any; }) => !v.ignore).length != 0 : false


export const formatDate = (date) => {
  return moment(date).format(`YYYY-MM-DD HH:mm:ss`)
}

export const setChoseMonitorApp = (name, key) => {
  localStorage.setItem('MONITOR_APP_NAME', name);
  localStorage.setItem('MONITOR_APP_KEY', key);
}

export const getChoseMonitorApp = () => {
  return {
    name: localStorage.getItem('MONITOR_APP_NAME'),
    key: localStorage.getItem('MONITOR_APP_KEY')
  }
}

export const safeJSONparse = (str: string) => {
  try {
    return JSON.parse(str || '{}')

  } catch (error) {

  }
  return {}
}